package com.lc.hongtai.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lc.hongtai.MyApplication;
import com.lc.hongtai.R;
import com.lc.hongtai.conn.JsonBorrowHuankuandetail;
import com.zcx.helper.bound.BoundViewHelper;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * Created by Administrator on 4/13/2016.
 */
public class BorrowingHuankuanAdapter extends RecyclerView.Adapter<BorrowingHuankuanAdapter.ViewHolder> {


    private Context context;
    private List<JsonBorrowHuankuandetail.Info.Repayment_list> list;


    public BorrowingHuankuanAdapter(Context context, List<JsonBorrowHuankuandetail.Info.Repayment_list> list) {
        this.context = context;
        this.list = list;

    }


    public static class ViewHolder extends RecyclerView.ViewHolder {

        @Bind(R.id.tv_03)
        TextView tv_03;
        @Bind(R.id.tv_qixian)
        TextView tv_qixian;
        @Bind(R.id.planned_repayment)
        TextView planned_repayment;
        @Bind(R.id.tv_benxi)
        TextView tv_benxi;

        @Bind(R.id.planned_lixi)
        TextView planned_lixi;
        @Bind(R.id.tv_status)
        TextView tv_status;

        @Bind(R.id.planned_time)
        TextView planned_time;
        @Bind(R.id.already_huan)
        TextView already_huan;


        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = BoundViewHelper.boundView(this, MyApplication.scaleScreenHelper.loadView((ViewGroup) LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_borrowinghuankuan, null)));
        // set the view's size, margins, paddings and layout parameters
        BorrowingHuankuanAdapter.ViewHolder vh = new BorrowingHuankuanAdapter.ViewHolder(view);

        return vh;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        //项目名称
        holder.tv_03.setText(list.get(position).borrow_id);


//实还本息
        holder.tv_qixian.setText(list.get(position).paid);
//计划还款本金
        holder.planned_repayment.setText(list.get(position).capital);
        //需还本息
        holder.tv_benxi.setText(list.get(position).needpay);


//计划利息
        holder.planned_lixi.setText(list.get(position).interest);
//还款状态
        holder.tv_status.setText(list.get(position).status);
        //需还本息
        holder.planned_time.setText(list.get(position).deadline);
        //还款状态
        if (list.get(position).status.equals("0")) {
            holder.already_huan.setText("立即还款");
            holder.already_huan.setBackground(context.getResources().getDrawable(R.drawable.shape_bg_login_bt));
            holder.already_huan.setTextColor(context.getResources().getColor(R.color.colorWhite));
        } else {
            holder.already_huan.setText("已还清");
        }


    }


    @Override
    public int getItemCount() {
        return list.size();
    }
}
